<template>
  <div :id="tabId" class="responsive-tabs">
    <ul class="resp-tabs-list">
      <li
        v-for="(tab, index) in tabs"
        :key="index"
        :class="['resp-tab-item', { 'resp-tab-active': index === activeTab }]"
        @click="setActiveTab(index)"
      >
        {{ tab.label }}
      </li>
    </ul>
    <div class="resp-tabs-container">
      <div
        v-for="(tab, index) in tabs"
        :key="index"
        v-show="index === activeTab"
        class="resp-tab-content"
      >
        <slot :name="tab.name"></slot>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, defineProps } from 'vue';

const props = defineProps({
  tabs: {
    type: Array,
    required: true
  },
  tabId: {
    type: String,
    default: 'defaultTab'
  }
});

const activeTab = ref(0);

function setActiveTab(index) {
  activeTab.value = index;
}
</script>

<style scoped>
.resp-tabs-list {
  list-style: none;
  padding: 0;
  display: flex;
}

.resp-tab-item {
  cursor: pointer;
  padding: 10px;
  background-color: #f5f5f5;
  margin-right: 5px;
}

.resp-tab-active {
  background-color: white;
  border-bottom: 2px solid #c1c1c1;
}

.resp-tabs-container {
  border: 1px solid #c1c1c1;
  padding: 10px;
}

.resp-tab-content {
  display: none;
}

.resp-tab-content.active {
  display: block;
}
</style>
